package com.company.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.company.project.command.inventory.InventoryCommand;
import com.company.project.command.inventory.InventoryCreateOrUpdateCommand;
import com.company.project.command.warehouse.WarehouseCreateorUpdateCommand;
import com.company.project.common.utils.DataResult;
import com.company.project.entity.inventoryLocation.InventoryLocation;
import com.company.project.service.HttpSessionService;
import com.company.project.service.inventory.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;

@RequestMapping("/inventory")
@RestController
public class InventoryController {
    @Autowired
    private InventoryService inventoryService;
    @Autowired
    private HttpSessionService sessionService;

    /**
     * 数据展现
     * @param command
     * @return
     */
    @PostMapping("/list")
    public DataResult list(@RequestBody InventoryCommand command){
        IPage<InventoryLocation> inventoryResult = this.inventoryService.selectselectAllTables(command);
        return DataResult.success(inventoryResult);
    }

    /**
     * 新增
     */
    @PostMapping("/create")
    public DataResult create(@RequestBody InventoryCreateOrUpdateCommand command){
        command.setId(sessionService.getCurrentUserId());
        command.setCreatedBy(sessionService.getCurrentUsername());
        this.inventoryService.create(command);
        return DataResult.success();
    }



}
